package com.dsiab.portalService.controller;

import com.dsiab.portalService.common.ResponseMap;
import com.dsiab.portalService.entity.PromoteDto;
import com.dsiab.portalService.service.PromoteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/promote")
@Slf4j
public class PromoteController {
  @Autowired
  PromoteService promoteService;


  @GetMapping("/getList/{page}")
  public ResponseMap getListPage(@PathVariable("page") String page)  {
    Map resultMap= new HashMap();
    List<PromoteDto> tbkDtos = promoteService.getList(Integer.parseInt(page));
    resultMap.put("result", tbkDtos);
    resultMap.put("total", promoteService.getListTotal());
    return new ResponseMap(0, "查询成功", resultMap);
  }

  @GetMapping("/getDetail/{id}")
  public ResponseMap getOne(@PathVariable("id") String id) {
    Map<String, Object> resultMap = new HashMap<>();
    // 浏览量加1
    promoteService.updateViews(Integer.valueOf(id));
    resultMap.put("result",promoteService.getDetail(id));
    return new ResponseMap(0, "查询成功", resultMap);
  }

  @GetMapping("/getRecommend")
  public ResponseMap getRecommend()  {
    Map resultMap= new HashMap();
    List<PromoteDto> tbkDtos = promoteService.getRecommend();
    resultMap.put("result", tbkDtos);
    return new ResponseMap(0, "查询成功", resultMap);
  }
}